<!DOCTYPE html>





<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.7.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.4.0">
  <link rel="mask-icon" href="/images/logo.svg?v=7.4.0" color="#222">

<link rel="stylesheet" href="/css/main.css?v=7.4.0">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.4.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="LOCAL_PATH := $(call my-dir)这条语句出现在Android.mk最开始。由于我们将所有源码等文件都存在了当前目录或子目录，因此调用my-dir这个函数来告知编译器所编译的模块在mk所在当前目录下。">
<meta name="keywords" content="android">
<meta property="og:type" content="article">
<meta property="og:title" content="Android.mk学习笔记">
<meta property="og:url" content="https://ricky9090.github.io/2016/08/02/android_mk_note/index.html">
<meta property="og:site_name" content="Ricky&#39;s Blog">
<meta property="og:description" content="LOCAL_PATH := $(call my-dir)这条语句出现在Android.mk最开始。由于我们将所有源码等文件都存在了当前目录或子目录，因此调用my-dir这个函数来告知编译器所编译的模块在mk所在当前目录下。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-06-11T08:46:43.931Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android.mk学习笔记">
<meta name="twitter:description" content="LOCAL_PATH := $(call my-dir)这条语句出现在Android.mk最开始。由于我们将所有源码等文件都存在了当前目录或子目录，因此调用my-dir这个函数来告知编译器所编译的模块在mk所在当前目录下。">
  <link rel="canonical" href="https://ricky9090.github.io/2016/08/02/android_mk_note/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>Android.mk学习笔记 | Ricky's Blog</title>
  








  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">
  <div class="container use-motion">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Ricky's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">A long way to go.</p>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-about">
      
    

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-tags">
      
    

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
            

          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
      <article itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block post">
    <link itemprop="mainEntityOfPage" href="https://ricky9090.github.io/2016/08/02/android_mk_note/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Ricky">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Ricky's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">Android.mk学习笔记

          
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2016-08-02 19:05:12" itemprop="dateCreated datePublished" datetime="2016-08-02T19:05:12+08:00">2016-08-02</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2018-06-11 16:46:43" itemprop="dateModified" datetime="2018-06-11T16:46:43+08:00">2018-06-11</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="LOCAL-PATH-call-my-dir"><a href="#LOCAL-PATH-call-my-dir" class="headerlink" title="LOCAL_PATH := $(call my-dir)"></a><strong>LOCAL_PATH := $(call my-dir)</strong></h2><p>这条语句出现在<code>Android.mk</code>最开始。由于我们将所有源码等文件都存在了当前目录或子目录，因此调用<code>my-dir</code>这个函数来告知编译器所编译的模块在mk所在当前目录下。</p>
<a id="more"></a>
<h2 id="LOCAL-MODULE"><a href="#LOCAL-MODULE" class="headerlink" title="LOCAL_MODULE"></a><strong>LOCAL_MODULE</strong></h2><p>这个参数是模块的名称，要求全局唯一并且不能带空格。<br>可以简单试验一下，找到任意一个模块的目录，例如<code>device/generic/goldfish</code>，这是虚拟机设备路径，新建一个文件夹<code>mymodule</code>，将其他模块（如gps）的<code>Android.mk</code>拷贝过来。<br>接下来在源码目录执行<code>make</code>，由于我们没有修改<code>Android.mk</code>文件的内容，导致出现了两个gps模块，因此编译报错：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">including ./device/generic/goldfish/mymodule/Android.mk ...</span><br><span class="line">build/core/base_rules.mk:157: *** device/generic/goldfish/mymodule: MODULE.TARGET.SHARED_LIBRARIES.gps.goldfish already defined by device/generic/goldfish/gps.  Stop.</span><br><span class="line"></span><br><span class="line">#### make failed to build some targets (31 seconds) ####</span><br></pre></td></tr></table></figure></p>
<p><br></p>
<h2 id="include-CLEAR-VARS"><a href="#include-CLEAR-VARS" class="headerlink" title="include $(CLEAR_VARS)"></a><strong>include $(CLEAR_VARS)</strong></h2><p>此参数要和后面的<code>include $(BUILD_*)</code>成对出现。每个模块编以前都要使用这条语句。<br><code>CLEAR_VARS</code>会通知编译系统清除一系列<strong>LOCAL</strong>环境变量<code>LOCAL_XXX</code>。</p>
<h2 id="include-BUILD-X"><a href="#include-BUILD-X" class="headerlink" title="include $(BUILD_X)"></a><strong>include $(BUILD_X)</strong></h2><p>其中：<br><code>BUILD_SHARED_LIBRARY</code>代表将模块编译成动态库<br><code>BUILD_STATIC_LIBRARY</code>代表将模块编译成静态库</p>
<p>接下来可以再测试一下，将<code>CLEAR_VARS</code>从<code>Android.mk</code>中删除，但保留<code>BUILD_SHARED_LIBRARY</code>，进行编译，则会报错：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">including ./device/generic/goldfish/mymodule/Android.mk ...</span><br><span class="line">build/core/shared_library_internal.mk:17: *** device/generic/goldfish/mymodule: Illegal use of OVERRIDE_BUILT_MODULE_PATH.  Stop.</span><br><span class="line"></span><br><span class="line">#### make failed to build some targets (31 seconds) ####</span><br></pre></td></tr></table></figure></p>
<p><br><br>当然把这一对参数都删掉整个rom是可以编译通过的，但因为在这个模块的<code>Android.mk</code>中没有声明编译库的类型，等于没有任何操作，仅仅include了一下。</p>

    </div>

    
    
    
        
      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/tags/android/" rel="tag"># android</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/2016/08/02/android_source_error/" rel="next" title="MacOS下编译Android源码报错：Can not find SDK 10.6 at">
                  <i class="fa fa-chevron-left"></i> MacOS下编译Android源码报错：Can not find SDK 10.6 at
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/2016/08/04/quick_sort_note/" rel="prev" title="快速排序">
                  快速排序 <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">
        
        
        
        
      

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#LOCAL-PATH-call-my-dir"><span class="nav-number">1.</span> <span class="nav-text">LOCAL_PATH := $(call my-dir)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#LOCAL-MODULE"><span class="nav-number">2.</span> <span class="nav-text">LOCAL_MODULE</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#include-CLEAR-VARS"><span class="nav-number">3.</span> <span class="nav-text">include $(CLEAR_VARS)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#include-BUILD-X"><span class="nav-number">4.</span> <span class="nav-text">include $(BUILD_X)</span></a></li></ol></div>
        
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Ricky</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">54</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/ricky9090" title="GitHub &rarr; https://github.com/ricky9090" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Ricky</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.7.1</div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.4.0</div>

        












        
      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js?v=3.1.0"></script>
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="/js/utils.js?v=7.4.0"></script><script src="/js/motion.js?v=7.4.0"></script>
<script src="/js/schemes/pisces.js?v=7.4.0"></script>

<script src="/js/next-boot.js?v=7.4.0"></script>



  





















  

  

  

</body>
</html>
